package phoneregistration.controller.converter.impl;

import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import phoneregistration.controller.converter.CompanyConverter;
import phoneregistration.controller.model.CompanyModel;
import phoneregistration.domain.Company;

@Service
public class CompanyConverterImpl implements CompanyConverter {

    public CompanyModel convertEntityToModel(Company e) {
        assertEntity(e);

        CompanyModel model = new CompanyModel();
        model.setId(e.getId());
        model.setName(e.getName());

        return model;
    }

    private void assertEntity(Company e) {
        Assert.notNull(e);
        Assert.notNull(e.getId());
        Assert.notNull(e.getName());
    }

    public Company convertModelToEntity(CompanyModel e) {
        assertModel(e);

        String id = e.getId();

        Company entity = new Company();
        entity.setId(id);
        entity.setName(e.getName());

        return entity;
    }

    private void assertModel(CompanyModel e) {
        Assert.notNull(e);
        Assert.notNull(e.getId());
        Assert.notNull(e.getName());
    }
}
